﻿// <copyright file="LogViewer.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Contains the LogViewer class.</summary>

namespace Sqwarea.GameLogic.View
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Sqwarea.Persistence;

    /// <summary>
    /// MapViewer class, implementation of IMapViewer
    /// </summary>
    public class LogViewer : ILogViewer
    {
        /// <summary>
        /// the log provider
        /// </summary>
        private readonly ILogProvider _logProvider;

        /// <summary>
        /// the game provider
        /// </summary>
        private readonly IGameProvider _gameProvider;

        /// <summary>
        /// Initializes a new instance of the LogViewer class
        /// </summary>
        /// <param name="gameProvider">the game provider used</param>
        /// <param name="logProvider">the log provider used</param>
        public LogViewer(IGameProvider gameProvider, ILogProvider logProvider)
        {
            if (null == logProvider)
            {
                throw new ArgumentNullException("logProvider");
            }

            if (null == gameProvider)
            {
                throw new ArgumentNullException("gameProvider");
            }

            this._gameProvider = gameProvider;
            this._logProvider = logProvider;
        }

        /// <summary>
        /// Gets the view of kingId user related to the logs.
        /// </summary>
        /// <param name="kingId">Id of the required king</param>
        /// <returns>See summary</returns>
        public IEnumerable<LogView> GetLogs(long kingId)
        {
            var kingsCache = new KingsCache(_gameProvider);
            return from log in this._logProvider.GetLogs(kingId) select new LogView(log, kingsCache);
        }
    }
}
